﻿using System;
using System.Web.Mvc;
using YiCheap.Service.Posts;
using YiCheap.Web.Models.Posts;

namespace YiCheap.Web.Controllers
{
    public class PostController : OptController
    {
        private IPostService _postService;

        private const int pageSize = 30;

        public ActionResult Index()
        {
            var startTime = DateTime.Now.AddMonths(-1);
            var endTime = DateTime.Now;

            var posts= _postService.SearchPost(startTime, endTime, 0, pageSize);

            var model = new PurchaseIndexModel()
                {
                    Posts = posts
                };

            return View("Index", model);
        }

        public ActionResult Create()
        {
            var model = new PostAddOrEditModel();
            return View("AddOrEdit", model);
        }

        [HttpPost]
        public JsonResult Create(PostAddOrEditModel model)
        {

            var request = new PostRequest()
                {
                    //Owner = this.GetCurrentUser(),
                    //CreatedDate = DateTime.Now,
                    //Product = model.ProductVariant
                };

            _postService.PurchaseProduct(request);


            return null;
        }

    }
}
